package com.swotxu.mall.ware.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.swotxu.common.utils.PageUtils;
import com.swotxu.common.utils.Query;
import com.swotxu.mall.ware.dao.PurchaseDetailDao;
import com.swotxu.mall.ware.entity.PurchaseDetailEntity;
import com.swotxu.mall.ware.service.PurchaseDetailService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import java.util.Map;


@Service("purchaseDetailService")
public class PurchaseDetailServiceImpl extends ServiceImpl<PurchaseDetailDao, PurchaseDetailEntity> implements PurchaseDetailService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        LambdaQueryWrapper<PurchaseDetailEntity> lambdaQueryWrapper = new LambdaQueryWrapper<>();

        String key = (String) params.get("key");    // 检索
        lambdaQueryWrapper.and(StringUtils.isNotEmpty(key), wrapper -> {
            wrapper.eq(PurchaseDetailEntity::getSkuId, key)
                    .or().eq(PurchaseDetailEntity::getPurchaseId, key);
        });

        String status = (String) params.get("status");  // 状态
        lambdaQueryWrapper.eq(StringUtils.isNotEmpty(status), PurchaseDetailEntity::getStatus, status);

        String wareId = (String) params.get("wareId");  // 仓库id
        lambdaQueryWrapper.eq(StringUtils.isNotEmpty(wareId), PurchaseDetailEntity::getWareId, wareId);

        IPage<PurchaseDetailEntity> page = this.page(
                new Query<PurchaseDetailEntity>().getPage(params),
                lambdaQueryWrapper
        );

        return new PageUtils(page);
    }

}